import java.sql.*
import groovy.sql.Sql

class Example {
    static void main(String[] args){
        // creating a connection to the database
        def sql = Sql.newInstance('jdbc:mysql://localhost:3306/demo?useSSL=false','root','1234','com.mysql.jdbc.Driver')

        def firstname = "tom"
        def lastname = "Molhan"
        def age = 20
        def sex = true
        def income = 2050
        sql.connection.autoCommit = false
        def sqlstr = "insert into Employee(first_name,last_name,age,sex,income) values (${firstname},${lastname},${age},${sex},${income})"
        
        try{
            sql.execute(sqlstr)
            sql.commit()
            println("Successfully committed")
        }catch(Exception ex){
            sql.rollback()
            println("Transaction rollback")
        }
        sql.close()
    }
}